package com.serv.common.base;

import java.util.List;
import java.util.UUID;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

public abstract class BaseService<M extends Model<M>> {
	protected M dao = null;
	
	protected BaseService() {}
	
	public String uuid(){
		return UUID.randomUUID().toString().replace("-", "").toLowerCase();
	}
	
	public Page<M> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras) {
		return dao.paginate(pageNumber, pageSize, select, sqlExceptSelect,paras);
	}
	
	public Page<M> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect) {
		return dao.paginate(pageNumber, pageSize, select, sqlExceptSelect);
	}
	
	public Page<M> paginate(int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras) {
		return dao.paginate(pageNumber, pageSize, isGroupBySql, select, sqlExceptSelect,paras);
	}
	
	public Page<M> paginateByFullSql(int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras) {
		return dao.paginateByFullSql(pageNumber, pageSize, totalRowSql, findSql, paras);
	}
	
	public Page<M> paginateByFullSql(int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras) {
		return dao.paginateByFullSql(pageNumber, pageSize, isGroupBySql, totalRowSql, findSql, paras);
	}
	
	public boolean deleteById(Object idValue){
		return dao.deleteById(idValue);
	}
	
	public boolean deleteById(Object... idValues){
		return dao.deleteById(idValues);
	}
	
	public M findById(String id) {
		return dao.findById(id);
	}
	
	public M findById(Object... idValues) {
		return dao.findById(idValues);
	}
	
	public List<M> find(String sql) {
		return dao.find(sql);
	}
	
	public List<M> find(String sql, Object... paras) {
		return dao.find(sql, paras);
	}
	
	public M findFirst(String sql, Object... paras) {
		return dao.findFirst(sql,paras);
	}
	
	public M findFirst(String sql) {
		return dao.findFirst(sql);
	}
	
	public M findByIdLoadColumns(Object idValue, String columns){
		return dao.findByIdLoadColumns(idValue,columns);
	}
	
	public M findByIdLoadColumns(Object[] idValues, String columns){
		return dao.findByIdLoadColumns(idValues,columns);
	}
	
	public List<M> findByCache(String cacheName, Object key, String sql, Object... paras) {
		return dao.findByCache(cacheName, key, sql, paras);
	}
	
	public List<M> findByCache(String cacheName, Object key, String sql) {
		return dao.findByCache(cacheName, key, sql);
	}
	
	public M findFirstByCache(String cacheName, Object key, String sql, Object... paras) {
		return dao.findFirstByCache(cacheName, key, sql, paras);
	}
	
	public M findFirstByCache(String cacheName, Object key, String sql) {
		return dao.findFirstByCache(cacheName, key, sql);
	}
	
	public Page<M> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras) {
		return dao.paginateByCache(cacheName,key,pageNumber,pageSize,select,sqlExceptSelect,paras);
	}
	
	public Page<M> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect) {
		return dao.paginateByCache(cacheName, key, pageNumber, pageSize, select, sqlExceptSelect);
	}
	
	public Page<M> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras) {
		return dao.paginateByCache(cacheName, key, pageNumber, pageSize, isGroupBySql, select, sqlExceptSelect, paras);
	}
	
	public List<M> find(SqlPara sqlPara) {
		return dao.find(sqlPara);
	}
	
	public M findFirst(SqlPara sqlPara) {
		return dao.findFirst(sqlPara);
	}
	
	public Page<M> paginate(int pageNumber, int pageSize, SqlPara sqlPara) {
		return dao.paginate(pageNumber, pageSize, sqlPara);
	}
}
